﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinServiceFileListener;

namespace ConsoleTestService
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string filePath = @"E:\Company\广医附一（横琴）\GyfyHqKrGuide\Common\bin\x86\Debug\Common.dll"; // 替换为你的文件路径
            string dateFolderName = DateTime.Now.ToString("yyyyMMdd");
            string destinationDirectory = Path.Combine(filePath, "..", dateFolderName);
            // 获取上级目录
            string parentDirectory = GetParentDirectory(filePath);

            Console.WriteLine($"上级目录是: {parentDirectory}");

            FolderListener myService = new FolderListener();
            FileListener FileListener = new FileListener();
            string key = "";
            while (key.ToUpper() != "Y")
            {
                FileListener.StartService(args);

                Console.WriteLine("是否需要退出并停止服务？ Y/N");
                key = Console.ReadLine();
            }
            FileListener.StopService();
        }
        public static string GetParentDirectory(string filePath)
        {
            // 获取文件的目录
            string directory = Path.GetDirectoryName(filePath);

            if (directory != null) // 确保目录不为 null
            {
                // 获取上级目录
                DirectoryInfo parentDirInfo = Directory.GetParent(directory);
                return parentDirInfo?.FullName; // 返回上级目录的完整路径
            }

            return null; // 如果无法找到上级目录则返回 null
        }
    }
}
